package com.example.e.Adapter

import android.view.LayoutInflater
import android.view.View
import android.view.ViewGroup
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.example.e.R
import com.example.e.data.ShouhuoAddress

class ShouhuoAddressAdapter (val shouhuo_address_data:List<ShouhuoAddress>):
    RecyclerView.Adapter<ShouhuoAddressAdapter.ShouhuoAddressViewHolder>() {

    class ShouhuoAddressViewHolder(view: View): RecyclerView.ViewHolder(view){
        val tvshouhuo_name: TextView = view.findViewById(R.id.tvshouhuo_name)
        val tvshouhuo_number: TextView = view.findViewById(R.id.tvshouhuo_number)
        val tvshouhuo_address: TextView = view.findViewById(R.id.tvshouhuo_address)
    }


    override fun onCreateViewHolder(parent: ViewGroup, viewType: Int): ShouhuoAddressViewHolder {
        val view = LayoutInflater.from(parent.context).inflate(R.layout.elem_shouhuoaddress_layout,parent,false)
        return ShouhuoAddressViewHolder(view)
    }

    override fun onBindViewHolder(holder: ShouhuoAddressViewHolder, position: Int) {
        if (!shouhuo_address_data.isEmpty()) {
            val info = shouhuo_address_data[position]
            holder.tvshouhuo_name.text = "${info.shouhuo_name}"
            holder.tvshouhuo_number.text = "${info.shouhuo_number}"
            holder.tvshouhuo_address.text = "${info.shouhuo_address}"
        }
    }
    override fun getItemCount() = shouhuo_address_data.size
}